package me.ahoukuse.koala.controller;

import com.alibaba.fastjson2.JSONObject;
import me.ahoukuse.koala.po.SharedFiles;
import me.ahoukuse.koala.service.SharedService;
import me.ahoukuse.koala.util.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/share")
public class SharedController {

    @Autowired
    SharedService sharedService;

    @GetMapping("getSharedByUserId")
    public JSONObject getSharedByUserId() {
        int userId = JwtUtil.getUserIdFromJwt();
        return sharedService.getSharedByUserId(userId);
    }

    @GetMapping("getSharedBySharedCode")
    public JSONObject getSharedBySharedCode(String sharedCode) {
        return sharedService.getSharedBySharedCode(sharedCode);
    }

    @PostMapping("updateSharedBySharedCode")
    public JSONObject updateSharedBySharedCode(SharedFiles sharedFiles) {
        // TODO 权限校验
        return sharedService.updateSharedBySharedCode(sharedFiles);
    }
}
